/*
 * Created on 27/02/2004
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package org.potiorb.orb.iiop;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.SocketException;

public class SocketsWrapper extends TransportWrapper {

	private Socket service;
	private ObjectInputStream input;
	private ObjectOutputStream output;

	public SocketsWrapper(Socket service){
		this.service = service;
		try{
			input = new ObjectInputStream(service.getInputStream());
			output = new ObjectOutputStream(service.getOutputStream());
		}
		catch(IOException e){
			e.printStackTrace();
		}
	}
	public SocketsWrapper(String host, int port){
	try{
		service = new Socket(host,port);
		output = new ObjectOutputStream(service.getOutputStream());
		input = new ObjectInputStream(service.getInputStream());
	}
	catch(IOException e){
		e.printStackTrace();
	}
	}

	public void write(Object obj) throws SocketException {
		try {
			output.writeObject(obj);
			output.flush();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
                        throw new SocketException();
		}
	}

	public Object read() throws SocketException{
		try {
			try {
				return input.readObject();
			} catch (ClassNotFoundException e1) {
				e1.printStackTrace();
                                return null;
			}
		} catch (IOException e) {
			e.printStackTrace();
 		        throw new SocketException();
		}
	}

}
